﻿using AppSocketModel;
using AppSocketService.Account;
using AppSocketService.Company;
using BCGPSCommon;
using BCGPSMongoData;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

namespace AppSocketService.ProductPerson
{
    public class ProductPersonService : ServiceBase, IProductPersonService
    {
        private MongoDBCommand<ProductDto> mongoDBCommand = new MongoDBCommand<ProductDto>("Procuct");  
         

        public ProductPersonService()
        {
        }

        public ProductDto Get(string imei)
        {
            return mongoDBCommand.SelectDocumentAsync(s => s.IMEI == imei).GetAwaiter().GetResult();
        }

        public bool IsExist(string imei)
        {
            if (Get(imei) != null)
                return true;
            else
                return false;
        }
          
          

        #region 审查设备是否登记在产品库
        public void ProductCheck(string imei)
        {
            if (!IsExist(imei))
                throw new ArgumentException($"IMEI[{imei}]设备不在公司产品库,请检查输入是否正确!"); 
        }
        #endregion
    }
}